home *** CD-ROM | disk | FTP | other *** search
/ Champak 29 / Volume 29 - JOGO DISK .iso / Games / jungle_adventure.swf / scripts / __Packages / SSShape.as < prev    next >
Text File  |  2006-11-29  |  7KB  |  204 lines

  1. class SSShape extends SSObject
  2. {
  3.    var isInstance = false;
  4.    var disabled = false;
  5.    var assetID = null;
  6.    var depthLayer = 2;
  7.    var className = "Shape";
  8.    var setShape = Object.prototype.constructor;
  9.    var classID = SSGlobal.CLSID_SHAPE;
  10.    var editor_name = "Shape";
  11.    var editor_isItem = true;
  12.    var editor_tool = "CreateShape";
  13.    var editor_args_names = ["style"];
  14.    var editor_args_values = ["DSGeneric"];
  15.    var editor_args_types = ["string"];
  16.    var editor_args_options = [["DSGeneric"]];
  17.    var editor_args_descriptions = [];
  18.    var editor_args_mode = [0];
  19.    var editor_args_component = ["List"];
  20.    var editor_commands = ["Reverse"];
  21.    var editor_canChangeAsset = false;
  22.    var editor_canChangeFrame = false;
  23.    var editor_canChangeName = false;
  24.    var editor_nullDefaultsOnSave = false;
  25.    function SSShape(style)
  26.    {
  27.       super();
  28.       if(this.isInstance || arguments.length < 1)
  29.       {
  30.          return undefined;
  31.       }
  32.       this.style = !(style != null && typeof style != "string") ? SSDrawStyle : style;
  33.       var _loc5_ = arguments.slice(1);
  34.       this.points = [];
  35.       var _loc4_ = _loc5_.length;
  36.       while((_loc4_ = _loc4_ - 1) > -1)
  37.       {
  38.          this.points.push(new SSShapeVertex(_loc5_[_loc4_ = _loc4_ - 1],_loc5_[_loc4_ = _loc4_ - 1],_loc5_[_loc4_ + 3]));
  39.       }
  40.       this.points[0].props = _loc5_[2];
  41.       this.points.reverse();
  42.       this.build();
  43.    }
  44.    function onAddToWorld()
  45.    {
  46.       if(this.drawStyle.store)
  47.       {
  48.          this.world.addToCollection(this.drawStyle.className,this);
  49.       }
  50.    }
  51.    function updateBounds()
  52.    {
  53.       var _loc2_ = this.leftSector != (this.leftSector = Math.floor((this.left = this.x + this.localLeft) / SSGlobal.GRID_SIZE));
  54.       var _loc3_ = this.topSector != (this.topSector = Math.floor((this.top = this.y + this.localTop) / SSGlobal.GRID_SIZE));
  55.       var _loc4_ = this.rightSector != (this.rightSector = Math.floor((this.right = this.x + this.localRight) / SSGlobal.GRID_SIZE));
  56.       var _loc5_ = this.bottomSector != (this.bottomSector = Math.floor((this.bottom = this.y + this.localBottom) / SSGlobal.GRID_SIZE));
  57.       if(_loc2_ || _loc3_ || _loc4_ || _loc5_)
  58.       {
  59.          this.removeFromSectorGrid();
  60.          this.addToSectorGrid();
  61.       }
  62.    }
  63.    function build()
  64.    {
  65.       var _loc9_ = this.points.length - 1;
  66.       var _loc2_ = undefined;
  67.       var _loc3_ = undefined;
  68.       var _loc4_ = undefined;
  69.       var _loc8_ = undefined;
  70.       var _loc6_ = undefined;
  71.       var _loc7_ = undefined;
  72.       var _loc5_ = undefined;
  73.       _loc8_ = _loc6_ = this.points[_loc9_].x;
  74.       _loc7_ = _loc5_ = this.points[_loc9_].y;
  75.       this.colEdges = [];
  76.       this.edges = [];
  77.       this.edges[_loc9_] = new SSShapeEdge(this.points[_loc9_],this.points[0]);
  78.       while((_loc9_ = _loc9_ - 1) > -1)
  79.       {
  80.          this.edges[_loc9_] = new SSShapeEdge(this.points[_loc9_],this.points[_loc9_ + 1]);
  81.          this.points[_loc9_].index = _loc9_;
  82.          this.edges[_loc9_].next = this.edges[_loc9_ + 1];
  83.          this.edges[_loc9_ + 1].previous = this.edges[_loc9_];
  84.          _loc8_ = Math.min(this.points[_loc9_].x,_loc8_);
  85.          _loc6_ = Math.max(this.points[_loc9_].x,_loc6_);
  86.          _loc7_ = Math.min(this.points[_loc9_].y,_loc7_);
  87.          _loc5_ = Math.max(this.points[_loc9_].y,_loc5_);
  88.       }
  89.       _loc9_ = this.edges.length - 1;
  90.       this.edges[_loc9_].next = this.edges[0];
  91.       this.edges[0].previous = this.edges[_loc9_];
  92.       this.localLeft = _loc8_;
  93.       this.localRight = _loc6_;
  94.       this.localTop = _loc7_;
  95.       this.localBottom = _loc5_;
  96.       _loc9_ = this.edges.length;
  97.       while((_loc9_ = _loc9_ - 1) > -1)
  98.       {
  99.          _loc3_ = _loc2_ = this.edges[_loc9_].a;
  100.          _loc4_ = _loc2_.b;
  101.          _loc2_.shape = this;
  102.          _loc2_.center = new Vector(_loc3_.x + (_loc4_.x - _loc3_.x) * 0.5,_loc3_.y + (_loc4_.y - _loc3_.y) * 0.5);
  103.          _loc2_.radius = 0.5 * (_loc2_.length = _loc2_.span = new Vector(_loc4_.x - _loc3_.x,_loc4_.y - _loc3_.y).length);
  104.          if(_loc3_.x > _loc4_.x)
  105.          {
  106.             _loc2_.left = _loc4_.x;
  107.             _loc2_.right = _loc3_.x;
  108.          }
  109.          else
  110.          {
  111.             _loc2_.left = _loc3_.x;
  112.             _loc2_.right = _loc4_.x;
  113.          }
  114.          if(_loc3_.y > _loc4_.y)
  115.          {
  116.             _loc2_.top = _loc4_.y;
  117.             _loc2_.bottom = _loc3_.y;
  118.          }
  119.          else
  120.          {
  121.             _loc2_.top = _loc3_.y;
  122.             _loc2_.bottom = _loc4_.y;
  123.          }
  124.          _loc2_.direction = _loc2_.span.getNormalized();
  125.          _loc2_.normal = _loc2_.direction.cross();
  126.          _loc2_.angle = Math.atan2(_loc2_.direction.y,_loc2_.direction.x) * 180 / 3.141592653589793;
  127.          _loc2_.props = _loc3_.props;
  128.          if(_loc2_.props & 1)
  129.          {
  130.             this.colEdges.push(_loc2_);
  131.          }
  132.       }
  133.       _loc9_ = this.edges.length;
  134.       while((_loc9_ = _loc9_ - 1) > -1)
  135.       {
  136.          _loc2_ = this.edges[_loc9_];
  137.          (_loc2_.a.normal = new Vector(_loc2_.previous.normal.x + _loc2_.normal.x,_loc2_.previous.normal.y + _loc2_.normal.y)).normalize();
  138.          _loc2_.a.scale = 1 / _loc2_.a.normal.dot(_loc2_.normal);
  139.       }
  140.       (this.drawStyle = new this.style()).init(this.points,this.edges);
  141.       if(this.depthLayer != this.drawStyle.depthLayer)
  142.       {
  143.          this.depthLayer = this.drawStyle.depthLayer;
  144.          this.depth = this.calculateDepth();
  145.       }
  146.       if(this.inScene)
  147.       {
  148.          this.redraw();
  149.       }
  150.    }
  151.    function redraw()
  152.    {
  153.       this.removeDisplay();
  154.       this.addDisplay();
  155.    }
  156.    function onAddDisplay()
  157.    {
  158.       this.target._visible = !this.disabled;
  159.       if(this.drawStyle.depthLayer != null)
  160.       {
  161.          this.depthLayer = Number(this.drawStyle.depthLayer);
  162.          this.target.swapDepths(this.calculateDepth());
  163.       }
  164.       this.drawStyle.draw(this.target);
  165.    }
  166.    function editor_onInit(obj)
  167.    {
  168.       this.normals = [];
  169.       this.instances = [];
  170.       this.points = [];
  171.       var _loc4_ = obj.props.slice(obj.propNames.length);
  172.       obj.propOptions[10] = _global.__drawStyles;
  173.       var _loc3_ = _loc4_.length;
  174.       while((_loc3_ = _loc3_ - 1) > -1)
  175.       {
  176.          this.points.push(new Vector(Number(_loc4_[_loc3_ = _loc3_ - 1]),Number(_loc4_[_loc3_ = _loc3_ - 1]),Number(_loc4_[_loc3_])));
  177.       }
  178.    }
  179.    function editor_onDisplay(target, external)
  180.    {
  181.       target.drawClip.removeMovieClip();
  182.       var _loc4_ = target.createEmptyMovieClip("drawClip",0);
  183.       var _loc6_ = SSShape;
  184.       var _loc0_ = null;
  185.       var _loc5_ = this.shapeObj = {};
  186.       _loc5_.__proto__ = _loc6_.prototype;
  187.       _loc6_.apply(_loc5_,[_global[this.props[10]]].concat(this.props.slice(11)));
  188.       _loc5_.drawStyle.showInfo();
  189.       _loc5_.drawStyle.draw(_loc4_);
  190.       _loc4_ = target.createEmptyMovieClip("shape",1);
  191.       _loc4_.beginFill(13421806,0);
  192.       var _loc3_ = this.points.length;
  193.       _loc4_.moveTo(this.points[0].x,this.points[0].y);
  194.       while((_loc3_ = _loc3_ - 1) > -1)
  195.       {
  196.          _loc4_.lineTo(this.points[_loc3_].x,this.points[_loc3_].y);
  197.       }
  198.       _loc4_.endFill();
  199.    }
  200.    function editor_onSelect()
  201.    {
  202.    }
  203. }
  204.